package com.ruoyi.payment.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 支付配置类
 * 
 * @author ruoyi
 */
@Configuration
public class PaymentConfig
{
    @Value("${wx.pay.app-id}")
    private String appId;

    @Value("${wx.pay.mch-id}")
    private String mchId;

    @Value("${wx.pay.mch-key}")
    private String mchKey;

    @Value("${wx.pay.key-path}")
    private String keyPath;

    @Value("${wx.pay.notify-url}")
    private String notifyUrl;

    @Value("${wx.pay.trade-type}")
    private String tradeType;

    /**
     * 微信支付配置
     */
    @Bean
    public WxPayConfig wxPayConfig()
    {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(appId);
        payConfig.setMchId(mchId);
        payConfig.setMchKey(mchKey);
        payConfig.setKeyPath(keyPath);
        payConfig.setNotifyUrl(notifyUrl);
        payConfig.setTradeType(tradeType);
        return payConfig;
    }

    /**
     * 微信支付服务
     */
    @Bean
    public WxPayService wxPayService(WxPayConfig wxPayConfig)
    {
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(wxPayConfig);
        return wxPayService;
    }
}
